package com.cl.pattern.chain;

/**
 * 请假单抽象处理类
 */
public abstract class Handler {

    //该领导处理的请假天数区间

    private int numStart = 0;
    private int numEnd = 0;

    /**
     * 下个处理类
     */
    private Handler nextHandler;


    /**
     *  设置请假天数范围
     * @param numStart
     * @param numEnd
     */
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    /**
     * 设置下一处理节点
     * @param nextHandler
     */
    public void setNextHandler(Handler nextHandler){
        this.nextHandler = nextHandler;
    }

    //提交请假条
    public final void submit(LeaveBill leave){
        if(0 == this.numStart){
            return;
        }

        //如果请假天数达到该领导者的处理要求
        if(leave.getLeaveDays() >= this.numStart){
            this.handleLeave(leave);

            //如果还有上级 并且请假天数超过了当前领导的处理范围
            if(null != this.nextHandler && leave.getLeaveDays() > numEnd){
                //继续提交
                this.nextHandler.submit(leave);
            }
        }
    }

    /**
     * 各级领导处理请假条方法
     * @param leave
     */
    protected abstract void handleLeave(LeaveBill leave);
}